<template>
  <BasicModal v-bind="$attrs" destroyOnClose title="会员卡详情" :width="modalWidth" :footer="null" @register="registerModal">
    <Description size="middle" class="mt-3" title="会员信息" :column="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }" :data="userGoodsInfo.data" :schema="userInfoSchema" />
    <Description size="middle" class="mt-4" title="会员卡信息" :column="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }" :data="userGoodsInfo.data" :schema="userGoodsInfoSchema" />
  </BasicModal>
</template>
<script lang="ts" setup>
import { reactive, ref, unref } from 'vue';
import { BasicModal, useModalInner } from '@apps/antd-admin/src/components/modal';
import { DescItem, Description } from '@apps/antd-admin/src/components/description';
import { getUserGoodsDetail } from '../data/api';
import { useAppInject } from '@apps/antd-admin/src/hooks/web/use-app-inject';

const { getIsMobile } = useAppInject();
const modalWidth = ref('750px');
if (unref(getIsMobile)) {
  modalWidth.value = '80%';
}
const userInfoSchema: DescItem[] = [
  {
    field: 'userName',
    label: '会员姓名',
    span: 3,
  },
  {
    field: 'mobile',
    label: '手机号',
    span: 3,
  },
];

let userGoodsInfo: Recordable = reactive({ data: {} });
const userGoodsInfoSchema: DescItem[] = [
  {
    field: 'vipCardState',
    label: '会员卡状态',
    span: 3,
    render: (curVal, data) => {
      let vipCardStateArray = [
        { label: '待激活', value: 0 },
        { label: '正常', value: 1 },
        { label: '已过期', value: 2 },
        { label: '未开通', value: 3 },
        { label: '未通过', value: 4 },
        { label: '冻结', value: 5 },
        { label: '退卡中', value: 6 },
        { label: '已退卡', value: 7 },
        { label: '已转卡', value: 8 },
        { label: '已转赠', value: 9 },
      ];
      const vipCardState: any = vipCardStateArray.find(item => item.value == curVal);
      if (vipCardState) {
        return vipCardState.label;
      }
      return '';
    },
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    span: 3,
  },
  {
    field: 'goodsName',
    label: '卡种名称',
    span: 3,
  },
  {
    field: 'airportName',
    label: '开卡地区',
    span: 3,
  },
  {
    field: 'employeeName',
    label: '所属销售',
    span: 3,
  },
  {
    field: 'buyDate',
    label: '开卡日期',
    span: 3,
  },
  {
    field: 'identityType',
    label: '证件类型',
    span: 3,
    render: (curVal, data) => {
      let identityTypeArray = [
        { label: '身份证', value: 1 },
        { label: '护照', value: 2 },
        { label: '港澳通行证', value: 3 },
        { label: '台胞证', value: 4 },
        { label: '其他', value: 5 },
      ];
      const identityType: any = identityTypeArray.find(item => item.value == curVal);
      if (identityType) {
        return identityType.label;
      }
      return '';
    },
  },
  {
    field: 'identityNo',
    label: '证件号码',
    span: 3,
  },
  {
    field: 'sex',
    label: '会员性别',
    span: 3,
  },
  {
    field: 'age',
    label: '会员年龄',
    span: 3,
  },
  {
    field: 'companyName',
    label: '公司名称',
    span: 3,
  },
  {
    field: 'sourceType',
    label: '会员卡来源',
    span: 3,
    render: (curVal, data) => {
      let sourceTypeArray = [
        { label: '扫码注册', value: 1 },
        { label: '商城购买', value: 2 },
        { label: '销售新增', value: 3 },
        { label: '后台新增', value: 4 },
        { label: '后台导入', value: 5 },
        { label: '礼品卡接收', value: 6 },
        { label: '后台批量生成', value: 7 },
        { label: '销售赠送', value: 8 },
        { label: '代理商下单', value: 9 },
        { label: '企业下单', value: 10 },
      ];
      const sourceType: any = sourceTypeArray.find(item => item.value == curVal);
      if (sourceType) {
        return sourceType.label;
      }
      return '';
    },
  },
  {
    field: 'payAmount',
    label: '支付金额',
    span: 3,
  },
  {
    field: 'paywayName',
    label: '支付方式',
    span: 3,
  },
  {
    field: 'payInfoId',
    label: '支付Id',
    span: 3,
  },
  {
    field: 'heKaRemark',
    label: '合卡销售',
    span: 5,
  },
  {
    field: 'remark',
    label: '备注',
    span: 8,
  },
];

const [registerModal, { setModalProps }] = useModalInner(async data => {
  let record = data.record;
  getUserGoodsDetail({
    userGoodsId: record.userGoodsId,
    handlerName: 'appUserGoodsGetHandler',
  }).then(result => {
    console.info(result);
    userGoodsInfo.data = result;
  });
});
</script>
